package com.example.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.common.Result;
import com.example.demo.entity.Video;
import com.example.demo.entity.VideoInfo;
import com.example.demo.entity.VideoTag;
import com.example.demo.mapper.VideoInfoMapper;
import com.example.demo.mapper.VideoTagMapper;
import com.example.demo.utils.Util;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第五小组
 * @since 2021-08-04
 */
@RestController
@RequestMapping("/bilibili")
public class VideoInfoController {
    @Autowired
    VideoInfoMapper videoInfoMapper;

    @Autowired
    VideoTagMapper videoTagMapper;

    @GetMapping("/video_info")
    public Result video_info(@RequestParam("bv") String bv, HttpServletResponse response){
        Util.exec("\\脚本\\video_info.py",bv);
        Video video = new Video();
        VideoInfo videoInfo = videoInfoMapper.selectOne(new QueryWrapper<VideoInfo>().eq("BV_bid",bv));
        BeanUtils.copyProperties(videoInfo,video);
        VideoTag videoTag = videoTagMapper.selectOne(new QueryWrapper<VideoTag>().eq("BV_bid",bv));
        List<String> tagList = new ArrayList<>();
        tagList.add(videoTag.getTag0());
        tagList.add(videoTag.getTag1());
        tagList.add(videoTag.getTag2());
        tagList.add(videoTag.getTag3());
        tagList.add(videoTag.getTag4());
        tagList.add(videoTag.getTag5());
        tagList.add(videoTag.getTag6());
        tagList.add(videoTag.getTag7());
        tagList.add(videoTag.getTag8());
        tagList.add(videoTag.getTag9());
        video.setTag(tagList);
        return Result.succ(video);
//        return Result.succ(videoInfoMapper.findByBV(bv));
    }

}
